package com.yundahh.u8c.dao;

import com.yundahh.u8c.config.U8CConfig;
import com.yundahh.u8c.dao.base.U8CBaseDao;
import com.yundahh.u8c.entity.Bom;
import com.yundahh.u8c.entity.base.U8CResult;
import com.yundahh.u8c.enums.OperationType;
import com.yundahh.u8c.util.HttpUtils;
import com.yundahh.u8c.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BomDao extends U8CBaseDao<Bom> {
    @Override
    public Class<Bom> getClazz() {
        return Bom.class;
    }

    @Override
    public String getApiUrl() {
        return "/u8cloud/api/uapbd/bdbom";
    }

    public BomDao(U8CConfig config) {
        super(config);
    }

    public List<Bom> getBom(String unicode,String wlbm) throws IOException {
        if(StringUtils.isBlank(unicode) || StringUtils.isBlank(wlbm)) {
            throw new IllegalArgumentException("公司编码和物料编号不能为空");
        }
        String url= config.getServerUrl()+getApiUrl();
        HashMap params=new HashMap();
        params.put("pk_corp",unicode);//传参的时候pk_corp其实就是unitcode公司编码，u8c的问题
        params.put("wlbm",wlbm);
        U8CResult<Bom> result = send(OperationType.QUERY, params);
        return result.getResultData().getDatas();

    }

    public U8CResult<Bom> getBomList(String unicode,int pageNo,int pageSize) throws IOException {
        HashMap params=new HashMap();
        params.put("pk_corp",unicode);//传参的时候pk_corp其实就是unitcode公司编码，u8c的问题
        params.put("page_now",pageNo);
        params.put("page_size",pageSize);
        U8CResult<Bom> result = send(OperationType.QUERY, params);
        return result;
    }
}
